package com.ruoyi.project.drug.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.drug.domain.Drug_Message;
import com.ruoyi.project.drug.service.IDrug_MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/drug/message")
public class Drug_MessageController extends BaseController {
    @Autowired
    private IDrug_MessageService iDrug_messageService;

    /*
     * 查询
     * */
    @PreAuthorize("@ss.hasPermi('drug:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(Drug_Message drug_message) {
        startPage();
        List<Drug_Message> list = iDrug_messageService.selectDrug_MessageList(drug_message);
        return getDataTable(list);
    }

    /*
     * 添加
     * */
    @PreAuthorize("@ss.hasPermi('drug:message:add')")
    @Log(title = "药品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Drug_Message drug_message) {
        drug_message.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iDrug_messageService.insertDrug_Message(drug_message));
    }

    /*
     * 按条件查询
     * */
    @PreAuthorize("@ss.hasPermi('drug:message:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable Long messageId) {
        return AjaxResult.success(iDrug_messageService.selectById(messageId));
    }


    /*
     * 修改
     * */
    @PreAuthorize("@ss.hasPermi('drug:message:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Drug_Message drug_message) {
        drug_message.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(iDrug_messageService.updateDrug_Message(drug_message));
    }

    /*
     * 删除
     * */
    @PreAuthorize("@ss.hasPermi('drug:message:remove')")
    @Log(title = "药品管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds) {
        return toAjax(iDrug_messageService.deleteDrug_MessageByIds(messageIds));
    }


}
